<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>列表</title>
    <link rel="stylesheet" href="../static/css/styles.css" />
    <link rel="stylesheet" href="../static/css/font-awesome-4.7.0/css/font-awesome.min.css" />
    <script src="../static/js/jquery.min.js" type="text/javascript"></script>

</head>


<body>

    <div class="condition">
<!--        课程编号：<input type="text"> 课程名称：-->
<!--        <input type="text"> 任课教师：-->
<!--        <input type="text">-->
<!--        <button>-->
<!--				<i class="fa fa-search"></i>-->
<!--				查询-->
<!--			</button>-->
        <form action="{{ url_for('xuankelistse') }}" method="post" enctype="multipart/form-data">
            课程编号<input type="text" name="cid"> 课程名称：
            <input type="text" name="cname">上课时间：
            <input type="text" name="classtime">

            <button>
				<i class="fa fa-search" type="submit"></i>
				<input type="submit" value="查询">

			</button>
        </form>
    </div>
    <table class="tablelist" id="abcde ">
        <tr>
            <th>课程编号</th>
            <th>课程名称</th>
            <th>上限人数</th>
            <th>学分</th>
            <th> 开始时间</th>
            <th> 结束时间</th>
            <th>上课地点</th>
            <th>任课教师</th>
            <th>上课时间</th>
            <th>已选人数</th>
            <th width="160px">输入权重</th>
            <th width="250px ">操作</th>
        </tr>
<!--        <tr>-->
<!--            <td>课程编号</td>-->
<!--            <td>课程名称</td>-->
<!--            <td>上限人数</td>-->
<!--            <td>学分</td>-->
<!--            <td> 开始时间</td>-->
<!--            <td> 结束时间</td>-->
<!--            <td>上课地点</td>-->
<!--            <td>任课教师</td>-->
<!--            <td>上课时间</td>-->
<!--            <td>已选人数</td>-->
        {% for v in stu_info %}
        <tr>
<!--            <form method="post" action="http://127.0.0.1:8080/xuankeadd">-->
            <td>{{v[0]}}</td>
            <td>{{v[1]}}</td>
            <td>{{v[2]}}</td>
            <td>{{v[3]}}</td>
            <td>{{v[4]}}</td>
            <td>{{v[5]}}</td>
            <td>{{v[6]}}</td>
            <td>{{v[7]}}</td>
            <td>{{v[8]}}</td>
            <td>{{v[9]}}</td>
            <td>
                <input type="text" placeholder="请输入权重:" name="quanzhong" value="" id="{{v[0]}}" style="width: 80px;">

            </td>
            <td>
                <button class=" edit " onclick="fuu(this)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;确定选课
                </button>
            </td>
<!--            <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-->
<!--                <button class=" remove " id="dsad " onclick="chch() ">-->
<!--                        <i class="fa fa-remove "></i>-->
<!--                        修改权重-->
<!--                    </button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-->
<!--&lt;!&ndash;            </form>&ndash;&gt;-->
<!--                <button class="remove " id="dsad " onclick="cclear(this) ">-->
<!--                        <i class="fa fa-remove "></i>-->
<!--                        退课-->
<!--                    </button></td>-->
        </tr>
        {% endfor %}
    </table>
    </table>
    <table class="page ">
        <td>
            <button onclick="first(this) ">首页</button>
            <button onclick="prev(this) ">上一页</button>
            <button onclick="next(this) ">下一页</button>
            <button onclick="last(this) ">尾页</button>
            <input type=" text " class="page-no " name="pageNo " value="1 " />
            <button onclick="change(this) ">转</button>
        </td>

    </table>
    <script>
        var page = 1;
         var tabl = document.getElementById("abcde ");
        var maxo = 10;
         var heo = document.getElementById("heo");
        for (var i = 0; i < (tabl.rows.length - 1); i++) {
            tabl.rows[i + 1].style.display = 'none ';
        }

        for (var i = 0; i < maxo; i++)
            tabl.rows[i + 1].style.display = "table-row ";

        function vanish(num) {
            var limt = num * maxo;
            for (var i = 0; i < (tabl.rows.length - 1); i++) {
                tabl.rows[i + 1].style.display = 'none ';
            }

            if (limt > (tabl.rows.length - 1))
                limt = (tabl.rows.length - 1);
            for (var i = (num - 1) * maxo; i < limt; i++)
                tabl.rows[i + 1].style.display = "table-row ";
        }

        function first(id) {
            page = 1;
            vanish(page);
            id.parentNode.children[4].value = page;
        }

        function last(id) {
            var maxsu = 0;
            if ((tabl.rows.length - 1) % maxo == 0)
                maxsu = Math.floor((tabl.rows.length - 1) / maxo);
            else maxsu = Math.floor((tabl.rows.length - 1) / maxo) + 1;
            page = maxsu;
            vanish(page);
            id.parentNode.children[4].value = page;
        }

        function prev(id) {
            if (page > 1)
                page--;
            vanish(page);
            id.parentNode.children[4].value = page;
        }

        function next(id) {
            var maxsu = 0;
            if ((tabl.rows.length - 1) % maxo == 0)
                maxsu = Math.floor((tabl.rows.length - 1) / maxo);
            else maxsu = Math.floor((tabl.rows.length - 1) / maxo) + 1;
            if (page < maxsu)
                page++;
            id.parentNode.children[4].value = page;
            vanish(page);
        }

        function change(id) {
            if ((tabl.rows.length - 1) % maxo == 0)
                maxsu = Math.floor((tabl.rows.length - 1) / maxo);
            else maxsu = Math.floor((tabl.rows.length - 1) / maxo) + 1;
            page = id.parentNode.children[4].value;
            if (page > maxsu)
                page = maxsu;
            if (page < 0)
                page = 1;
            id.parentNode.children[4].value = page;
            vanish(page);
        }

        function fuu(id) {
            var x = parseInt({{quanzhong}});
            var uid=id.parentNode.parentNode.children[10].children[0];

            // alert(x);
            if ((parseInt(uid.value,10) + x) > 100) {

                alert("权重剩余" + (100 - x) + " 请重新输入权重！ ");
                uid.value = "";

            } else {
                 alert("你投的权重为"+uid.value+",你的剩余权重为" +(100-x-parseInt(uid.value,10)));
                x = x + parseInt(uid.value,10);
                var xml = new XMLHttpRequest();
                xml.open("get", "http://127.0.0.1:8080/xuankeadd/" + uid.value+'/'+uid.parentNode.parentNode.children[0].innerHTML, true); //x是权重，右边是课程id
                // xml.onreadystatechange = function () {
                //
                // };
                xml.send();
            }
            window.setTimeout("window.location.href='{{url_for('xuankelist')}}'",500);
        //window.location.href='{{url_for('xuankelist')}}'
        }

        function chch() {
            uid.removeAttribute('readOnly');
        }

        function cclear(p) {
            uid.removeAttribute('readOnly');
            uid.value = "";
            // 20:52 cjc
            var r = confirm("确认删除该信息？");
            if (r == true) {

                var cid = p.parentNode.parentNode.children[0].innerHTML;
                var cou = p.parentNode.parentNode.children[1].innerHTML;
                var xml = new XMLHttpRequest();
                xml.open("get", "http://127.0.0.1:8080/dropcour" + cid+'/'+cou, true);
                // xml.onreadystatechange = function () {
                //
                // };
                xml.send();
                // xml.send("callback=functionName");
                alert("删除成功");
                window.location.href = '{{url_for('xuankelist')}}';
            } else
                alert("信息未删除");
        }
    </script>
</body>

</html>